﻿package mortal.game.view.palyer
{
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.display.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.forging.data.*;

    public class PlayerEquipItem extends BaseItem
    {
        private var _category:int;
        private var _type:int;
        private var _disabledBg:ScaleBitmap;
        private var _isAvailable:Boolean = true;
        private var _isShowOverLight:Boolean;
        private var _maskBitMap:GBitmap;
        private var _overSwf:SWFPlayer;
        private var _selectBg:GBitmap;
        private var _canOperateImg:GImageBitmap;
        private var _strengNumPosType:int = 0;

        public function PlayerEquipItem()
        {
            _bitmap.x = 4;
            _bitmap.y = 4;
            return;
        }// end function

        public function get category() : int
        {
            return this._category;
        }// end function

        public function get type() : int
        {
            return this._type;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.mouseChildren = false;
            return;
        }// end function

        public function setLight(param1:Boolean, param2:int = 1) : void
        {
            switch(param2)
            {
                case ForgingConst.YellowFilter:
                {
                    break;
                }
                case ForgingConst.BlueFilter:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (this._bitmap != null)
            {
            }
            return;
        }// end function

        override public function set itemData(param1:ItemData) : void
        {
            super.itemData = param1;
            if (param1 == null)
            {
                this.clearStrengInfo();
                clearArroundEffect();
            }
            this.updateOverLightEffect();
            return;
        }// end function

        override protected function updateView() : void
        {
            super.updateView();
            this.updateStrengthPos();
            return;
        }// end function

        private function createOverLightEffect() : void
        {
            if (this._overSwf == null)
            {
                this._overSwf = UICompomentPool.getUICompoment(SWFPlayer);
                this._maskBitMap = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
                this.addChild(this._maskBitMap);
                this.addChild(this._overSwf);
                this._overSwf.mask = this._maskBitMap;
                this._overSwf.timeRate = 1;
                this._overSwf.playNum = 1;
                this._overSwf.stop();
                this._overSwf.load("playerOver.swf", ModelType.NormalSwf, null);
                this._maskBitMap.width = this.width;
                this._maskBitMap.height = this.height;
                this._overSwf.move(20, 21);
                this.configEventListener(MouseEvent.ROLL_OVER, this.showOverEffect);
            }
            return;
        }// end function

        private function clearOverLightEffect() : void
        {
            if (this._overSwf)
            {
                this._overSwf.mask = null;
                this._overSwf.dispose(true);
                this._overSwf = null;
                this._maskBitMap.dispose(true);
                this._maskBitMap = null;
                this.removeEventListener(MouseEvent.ROLL_OVER, this.showOverEffect);
            }
            return;
        }// end function

        public function set isShowOverLight(param1:Boolean) : void
        {
            if (this._isShowOverLight == param1)
            {
                return;
            }
            this._isShowOverLight = param1;
            this.updateOverLightEffect();
            return;
        }// end function

        private function updateOverLightEffect() : void
        {
            if (this._isShowOverLight && itemData)
            {
                this.createOverLightEffect();
            }
            else
            {
                this.clearOverLightEffect();
            }
            return;
        }// end function

        public function setSelEffect(param1:Boolean) : void
        {
            this.isSelect = param1;
            return;
        }// end function

        public function set isSelect(param1:Boolean) : void
        {
            if (param1)
            {
                if (this._selectBg == null)
                {
                    this._selectBg = UIFactory.gBitmap(ImagesConst.ForgingSelectBg, -6, -5, this);
                }
                this.setChildIndex(this._selectBg, 0);
                EffectManager.glowFilterReg(this._selectBg);
            }
            else if (this._selectBg)
            {
                EffectManager.glowFilterUnReg(this._selectBg);
                this._selectBg.dispose();
                this._selectBg = null;
            }
            return;
        }// end function

        private function showOverEffect(event:MouseEvent) : void
        {
            if (this._overSwf.currentFrame == (this._overSwf.totalFrames - 1) || this._overSwf.currentFrame == 0)
            {
                this._overSwf.play();
            }
            return;
        }// end function

        override public function updateStrengLevel(param1:int = 0) : void
        {
            super.updateStrengLevel(param1);
            this.updateStrengthPos();
            return;
        }// end function

        public function clearStrengInfo() : void
        {
            if (_txtStrenLv)
            {
                _txtStrenLv.text = "";
            }
            return;
        }// end function

        public function set isAvailable(param1:Boolean) : void
        {
            this._isAvailable = param1;
            if (this._isAvailable)
            {
                updateAroundEffect();
                if (this._disabledBg)
                {
                    this._disabledBg.dispose();
                    this._disabledBg = null;
                }
            }
            else
            {
                if (this._disabledBg == null)
                {
                    this._disabledBg = UIFactory.bg(0, 0, width, height, this, ImagesConst.PackDisable2);
                }
                this._disabledBg.width = _width - _paddingLeft * 2;
                this._disabledBg.height = _height - _paddingTop * 2;
                this._disabledBg.x = _paddingLeft;
                this._disabledBg.y = _paddingTop;
                clearArroundEffect();
            }
            return;
        }// end function

        public function get isAvailable() : Boolean
        {
            if (_itemData == null)
            {
                return false;
            }
            return this._isAvailable;
        }// end function

        public function updateEmbedState() : void
        {
            return;
        }// end function

        public function updateGemUpgradeState() : void
        {
            return;
        }// end function

        public function updateRefreshState() : void
        {
            this.isAvailable = EquipmentUtil.isCanRefresh(_itemData);
            return;
        }// end function

        public function updateColorAdvanceState() : void
        {
            this.isAvailable = EquipmentUtil.isCanColorAdvance(_itemData);
            return;
        }// end function

        public function updateStarAdvanceState() : void
        {
            this.isAvailable = EquipmentUtil.isCanStarAdvance(_itemData);
            return;
        }// end function

        public function addStrengUpEffect() : void
        {
            var _loc_1:TimelineLite = null;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            if (_txtStrenLv)
            {
                _loc_1 = new TimelineLite();
                _loc_2 = this._txtStrenLv.x;
                _loc_3 = this._txtStrenLv.y;
                _loc_4 = this._txtStrenLv.x - 10;
                _loc_5 = this._txtStrenLv.y - 10;
                _loc_1.append(new TweenLite(this._txtStrenLv, 0.17, {scaleX:2, scaleY:2, x:_loc_4, y:_loc_5}));
                _loc_1.append(new TweenLite(this._txtStrenLv, 0.17, {scaleX:1, scaleY:1, x:_loc_2, y:_loc_3}));
                _loc_1.play();
            }
            return;
        }// end function

        public function updateGemEmbedInfo() : void
        {
            return;
        }// end function

        public function clear() : void
        {
            this.clearStrengInfo();
            this.isAvailable = true;
            this.isCanOperate = false;
            return;
        }// end function

        public function set strengNumPosType(param1:int) : void
        {
            this._strengNumPosType = param1;
            this.updateStrengthPos();
            return;
        }// end function

        private function updateStrengthPos() : void
        {
            if (_txtStrenLv)
            {
                if (this._strengNumPosType == 0)
                {
                    _txtStrenLv.x = this.width - _txtStrenLv.width;
                    _txtStrenLv.y = this.height - _txtStrenLv.height - 2;
                }
                else if (this._strengNumPosType == 1)
                {
                    _txtStrenLv.x = -_txtStrenLv.width;
                    _txtStrenLv.y = this.height - _txtStrenLv.height - 2;
                }
                else if (this._strengNumPosType == 2)
                {
                    _txtStrenLv.x = this.width;
                    _txtStrenLv.y = this.height - _txtStrenLv.height + 1;
                }
                else if (this._strengNumPosType == 3)
                {
                    _txtStrenLv.x = this.width - _txtStrenLv.width + 2;
                    _txtStrenLv.y = -_txtStrenLv.height - 3;
                }
            }
            return;
        }// end function

        public function set isCanOperate(param1:Boolean) : void
        {
            if (param1)
            {
                if (this._canOperateImg == null)
                {
                    this._canOperateImg = UIFactory.gImageBitmap("", 5, -12, this);
                }
                this._canOperateImg.imgUrl = ImagesConst.ForgingCanOperate;
            }
            else if (this._canOperateImg)
            {
                this._canOperateImg.dispose();
                this._canOperateImg = null;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._selectBg)
            {
                this._selectBg.dispose(param1);
                this._selectBg = null;
            }
            if (this._disabledBg)
            {
                this._disabledBg.dispose(param1);
                this._disabledBg = null;
            }
            if (this._canOperateImg)
            {
                this._canOperateImg.dispose();
                this._canOperateImg = null;
            }
            this._isShowOverLight = false;
            this._strengNumPosType = 0;
            this.clearOverLightEffect();
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
